/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test3.problem2;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author hoang.pt
 */
public class Thread1 extends MyThread {

    public Thread1(Data d) {
        super(d);
    }

    /**
     * 
     */
    @Override
    public void run() {
        //get data
        this.getData();
    }

    /**
     * 
     */
    public void getData() {

        //continue for 2, 3
        int i = 0;
        while (i < 3) {
            //element 1
            //mark Data class only 1 access
            synchronized (this.d) {
                //check flag
                //--flag false then get data,
                if (!d.flag) {
                    //---change flag
                    d.flag = true;

                    //---get
                    String[] data = d.getData();
                    d.temp = data[i];

                    //---notify
                    d.notify();
                }

                try {
                    d.wait();
                } catch (InterruptedException ex) {
                    System.out.println("Wait is not finish. Mother want thread to eating");
                }
            }

        i++;

        }

    }
}
